package com.Bigbluebook.fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.Bigbluebook.Activity.CommentActivity;
import com.Bigbluebook.Activity.LikeActivity;
import com.Bigbluebook.Activity.StarActivity;
import com.Bigbluebook.R;



public class MineFragment extends Fragment {

    private Button likeButton;
    private Button commentButton;
    private Button star;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_mine, container, false);

        likeButton=view.findViewById(R.id.liked_btn);
        commentButton=view.findViewById(R.id.commented_btn);
        star=view.findViewById(R.id.btn3);
        TextView usernameTextView = view.findViewById(R.id.username_textview);
        // 假设你有一个方法来获取当前用户的用户名
        SharedPreferences sharedPreferences = getActivity().getSharedPreferences("user_info", Context.MODE_PRIVATE);
        String username = sharedPreferences.getString("username",null);
        usernameTextView.setText("用户名：" + username);
        likeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到我的喜欢页面
                Intent intent = new Intent(getActivity(), LikeActivity.class);
                startActivity(intent);
            }
        });

        // 设置我的评论按钮的点击事件
        commentButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到我的评论页面
                Intent intent = new Intent(getActivity(), CommentActivity.class);
                startActivity(intent);
            }
        });

        // 设置我的收藏按钮的点击事件
        star.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到我的收藏页面
                Intent intent = new Intent(getActivity(), StarActivity.class);
                startActivity(intent);
            }
        });
        return view;
    }
}
